/**
 *
 */
package org.insia.smartposse.manager.list;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.insia.smartposse.manager.FreelanceSkillManager;
import org.insia.smartposse.manager.UserManager;
import org.insia.smartposse.mapping.FreelanceSkills;
import org.insia.smartposse.mapping.dao.FreelanceSkillsDAO;

/**
 * Manage a list of FreelanceSkill
 *
 * @author cmougel
 *
 */
public final class FreelanceSkillsListManager extends ArrayList {

	private List<FreelanceSkills> _freelanceSkills = new ArrayList<FreelanceSkills>();
	private final FreelanceSkillsDAO _dao = new FreelanceSkillsDAO();

	/**
	 * Get All FreelanceSkill
	 *
	 */
	public FreelanceSkillsListManager(){
		_freelanceSkills = _dao.findAll();
	}
	
	public FreelanceSkillsListManager(UserManager user) {
		_freelanceSkills = _dao.findByUser(user, _dao.getSession());
	}

	/**
	 * Construct
	 * @param freelanceSkills
	 */
	public FreelanceSkillsListManager(Set<FreelanceSkills> freelanceSkills){
		_freelanceSkills = new ArrayList<FreelanceSkills>(freelanceSkills);
	}

	/**
	 * Destruct and close the session
	 */
	public void finalize(){
		FreelanceSkillsDAO.closeCurrentSession();
	}

	@Override
	public FreelanceSkillManager get(int index) {
		return new FreelanceSkillManager(_freelanceSkills.get(index));
	}

	@Override
	public int size() {
		return _freelanceSkills.size();
	}
}
